package fieldgame;

import boundaryToMatador.GUI;

public class UIManager {
	String[][] fieldNames = {
			{ "Start", "", "" },
			{
					"Tower",
					"You entered the tower and found great treasures everywhere!",
					"+250" },
			{ "Crater", "Bad luck, you got robbed", "-200" },
			{ "Palace Gates",
					"You have to pay an entrence fee, to enter the palace: ",
					"-100" },
			{ "Cold Dessert",
					"You have to keep warm in the cold dessert pay: ", "-20" },
			{ "Walled City", "Go collect your gold at the bank", "+180" },
			{ "Monastery", "Nothing happens here", "0" },
			{
					"Black Cave",
					"You entered the black cave, you hear some strange noices and drops:",
					"-70" },
			{ "Huts in the mountain", "You have to stay for some days, pay:",
					"-60" },
			{
					"The Werewall (werewolf-wall)",
					"You got so scared of the werewolf and are in such a hurry that you get an extra dice roll and drops:",
					"-80" },
			{ "The pit",
					"The pit is a bad place, to stay alive you have to pay:",
					"-90" },
			{
					"Goldmine",
					"Yes you are awsome! You found the amazing goldmine and gains: ",
					"+650" } };

	public UIManager() {
		Translate.init();
		GUI.create("fields.txt");

		for (int i = 0; i < fieldNames.length; i++) {
			GUI.setTitleText(i + 1, Translate.print(fieldNames[i][0]));
			GUI.setSubText(i + 1, fieldNames[i][2]);
			GUI.setDescriptionText(i + 1, Translate.print(fieldNames[i][1]));
		}
	}

	public int numberOfPlayersEvent(int min, int max) {
		return GUI.getUserInteger("Enter a number between " + min + " and "
				+ max + ".", min, max);
	}

	public void initPlayers(int startBalance, int numberOfPlayers) {
		for (int i = 0; i < numberOfPlayers; i++) {
			GUI.addPlayer(Integer.toString(i + 1), startBalance);
		}
	}

	public void displayWinner(int[] winners, int winnerBalance) {
		if (winners.length == 1)
			GUI.showMessage("The winner is player " + (winners[0]+1) + " with "
					+ winnerBalance + "!");
		else if (winners.length > 1) {
			String string = "";
			for (int i = 0; i < winners.length - 1; i++) {
				string += (winners[i]+1);
				if (i != winners.length - 2)
					string += ", ";
			}string += " and " + (winners[winners.length-1]+1);
			
			GUI.showMessage("The match ended in a tie between the players "
					+ string + " with " + winnerBalance + "!");
		}
	}

	public void updatePlayer(int number, int balance, int fieldIndex) {
		GUI.removeAllCars(Integer.toString(number + 1));
		GUI.setBalance(Integer.toString(number + 1), balance);
		GUI.setCar(fieldIndex + 2, Integer.toString(number + 1));
		GUI.showMessage("Player " + (number+1) + " entered the " + fieldNames[fieldIndex + 1][0] + ". "
				+ fieldNames[fieldIndex + 1][1] + " "
				+ fieldNames[fieldIndex + 1][2]);
	}

	public void shake(int diceSum, int dice1, int dice2, int currentPlayerIndex) {
		GUI.getUserButtonPressed("It's player " + (currentPlayerIndex + 1)
				+ "'s turn!", "shake");
		GUI.setDice(dice1, dice2);

	}

	public void reset(int startBalance, int numberOfPlayers) {
		for (int i = 0; i < numberOfPlayers; i++) {
			GUI.removeAllCars(Integer.toString(i + 1));
			GUI.setBalance(Integer.toString(i + 1), startBalance);
			GUI.setCar(1, Integer.toString(i + 1));
		}
	}

}
